﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Terralever.Facebook.UI.FbmlControls;

namespace Terralever.Facebook.UI
{
    /// <summary>
    /// NYI
    /// </summary>
    public class IFrameBasePage : Page
    {
        /// <inheritdoc />
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            CheckForFbmlControlsRecursive(Controls);
        }

        // Iterates recursively through all child controls and checks to see whether they're FBML controls.
        // If so, sets them to use XFBML semantics - that they always need an explicit closing tag
        // http://wiki.developers.facebook.com/index.php/XFBML
        private void CheckForFbmlControlsRecursive(ControlCollection controls)
        {
            foreach (Control c in controls)
            {
                FbmlControl fc = c as FbmlControl;
                if (fc != null)
                {
                    fc.UseXfbmlSemantics = true;
                }

                CheckForFbmlControlsRecursive(c.Controls);
            }
        }
    }
}
